/*
 * Copyright (C) 2007-2015 FBReader.ORG Limited <contact@fbreader.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

package org.geometerplus.zlibrary.core.view;

import android.view.MotionEvent;

import org.geometerplus.fbreader.book.Bookmark;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.text.view.ModelData;
import org.geometerplus.zlibrary.ui.android.view.animation.BaseAnimationProvider;

import java.util.List;

abstract public class ZLView implements ZLViewEnums {

    public final ZLApplication Application;

    /**
     * 构造子类传递
     *
     * @param application FBReaderApp实例
     */
    protected ZLView(ZLApplication application) {
        Application = application;
    }

    private ZLPaintContext myViewContext = new DummyPaintContext();

    /**
     * 绘制
     *
     * @param context   画笔信息
     * @param pageIndex 页面坐标
     */
    abstract public void paint(ZLPaintContext context, PageIndex pageIndex);


    public final void setContext(ZLPaintContext context) {
        myViewContext = context;
    }

    public final ZLPaintContext getContext() {
        return myViewContext;
    }

    /**
     * 绘制数据
     * @param modelData
     * @param context
     * @param pageIndex
     */
    abstract protected void paintModel(ModelData modelData, ZLPaintContext context, PageIndex pageIndex);

    /**
     * 得到ZLAndroidPaintContext的宽
     * @return
     */
    public final int getContextWidth() {
        return myViewContext.getWidth();
    }
    /**
     * 得到ZLAndroidPaintContext的高
     * @return
     */
    public final int getContextHeight() {
        return myViewContext.getHeight();
    }


    public interface FooterArea {

        int getHeight();

        void paint(ModelData modelData, ZLPaintContext context, PageIndex index);

    }

    public interface HeaderArea extends FooterArea {

    }

    abstract public FooterArea getFooterArea();

    abstract public FooterArea getHeaderArea();

    public abstract Animation getAnimationType();

    abstract public void doShiftPage(PageIndex pageIndex);

    public boolean onFingerPress(int x, int y) {
        return false;
    }

    public boolean onFingerRelease(BaseAnimationProvider.AnimationFling fling, int x, int y) {
        return false;
    }

    public boolean onFingerMove(int x, int y) {
        return false;
    }

    public boolean onFingerLongPress(int x, int y) {
        return false;
    }

    public boolean onFingerReleaseAfterLongPress(int x, int y) {
        return false;
    }

    public boolean onFingerMoveAfterLongPress(int x, int y) {
        return false;
    }

    public boolean onFingerSingleTap(int x, int y) {
        return false;
    }

    public boolean onFingerDoubleTap(int x, int y) {
        return false;
    }

    public boolean isDoubleTapSupported() {
        return false;
    }

    public boolean onTrackballRotated(int diffX, int diffY) {
        return false;
    }

    public abstract boolean isScrollbarShown();

    public abstract int getScrollbarFullSize();

    public abstract int getScrollbarThumbPosition(PageIndex pageIndex);

    public abstract int getScrollbarThumbLength(PageIndex pageIndex);

    public boolean preDoTouchEvent(MotionEvent event) {
        return false;
    }

    public abstract List<Bookmark> getBookmarksInPage(PageIndex index);

    public abstract List<Bookmark> getBookmarksInPage(ModelData modelData, PageIndex index);

    public List<Bookmark> getBookmarksInCurPage() {
        return getBookmarksInPage(PageIndex.current);
    }

    public abstract boolean canScroll(PageIndex index);

    /**
     * @param context
     * @param index
     * @return
     */
    public abstract boolean doProcessNoPageData(ZLPaintContext context, PageIndex index);

    private boolean mIsPendingLoadPageData;

    /**
     * @return the isPendingLoadPageData
     */
    public boolean isPendingLoadPageData() {
        return mIsPendingLoadPageData;
    }

    /**
     * @param
     */
    protected synchronized void startPendingLoadPageData() {
        mIsPendingLoadPageData = true;
    }

    public synchronized void stopPendingLoadPageData() {
        mIsPendingLoadPageData = false;
    }


}
